package com.kuang.operator;
public class Demo10 {
    public static void main(String[] args) {
        int[] str = {5,10,8,3,9,2,6,4,7,1};
        System.out.println("快速排序前：");
        int lean = str.length;
        for (int i=0;i<lean;i++){
            System.out.print(str[i]+" ");
        }
        System.out.println("\n");

        paixu(str,0,str.length-1);

        System.out.println("快速排序后面：");
        for (int i=0;i<lean;i++){
            System.out.print(str[i]+" ");
        }
    }
    public static void paixu(int[] num,int start,int end){
        if(start > end){
            return;
        }
        int key=num[start];
        int left=start;
        int right=end;
        while(left != right){
            while(right>left && num[right]>=key){
                right--;
            }
            while(right>left && num[left]<=key){
                left++;
            }
            if(left<right){
                int w=num[left];
                num[left]=num[right];
                num[right]=w;
            }
        }
        num[start]=num[left];
        num[left]=key;

        paixu(num,start,left-1);
        paixu(num,left+1,end);
    }
}
